package com.hmall.gateway.filter;

import lombok.Data;
import org.springframework.cloud.gateway.filter.GatewayFilter;
import org.springframework.cloud.gateway.filter.GatewayFilterChain;
import org.springframework.cloud.gateway.filter.factory.AbstractGatewayFilterFactory;
import org.springframework.http.server.ServerHttpResponse;
import org.springframework.stereotype.Component;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;

import java.util.List;

//局部路由配置11
@Component
public class prinAnyGatewayFiterFactory extends AbstractGatewayFilterFactory<prinAnyGatewayFiterFactory.Config> {

    @Override
    public GatewayFilter apply(Config config){
        return new GatewayFilter() {
            @Override
            public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
                //编写过滤器逻辑
                System.out.println("PrintAny filter 执行了");
                //放行
                return chain.filter(exchange);
            }
        };
    }
    //自定义配置属性，成员变量名称很重要，下面会用到
    @Data
     static class Config{
        private String name;
        private String city;
        private String sex;
    }

    //／将变量名称依次返回，顺序很重要，将来读取参数时需要按顺序获取
    // 将变量名称依次返回，顺序很重要，将来读取参数时需要按顺序获取
    @Override
    public List<String> shortcutFieldOrder() {
        return List.of("name","city","sex");
    }

    // 返回当前配置类的类型，也就是内部的Config

    public prinAnyGatewayFiterFactory() {
        super(Config.class);
    }
}
